package com.cgy.utils.spider.config;

import java.util.List;

import com.cgy.utils.spider.callback.AbstractCallBack;
import com.cgy.utils.spider.clone.Clone;
import com.cgy.utils.spider.cookie.Cookie;
import com.cgy.utils.spider.cookie.Cookies;
import com.cgy.utils.spider.element.AbstractElement;
import com.cgy.utils.spider.header.Header;
import com.cgy.utils.spider.header.Headers;
import com.cgy.utils.spider.resolver.AbstractResolver;
import com.google.common.collect.Lists;

import lombok.Data;

/**
 *  用于处理初始化配置
 * @author CH
 *
 */
@Data
public abstract class AbstractConfig implements Clone{

	private List<AbstractElement> elements;
	private AbstractResolver resolver;
	
	public AbstractConfig() {
		this.elements = Lists.newArrayList();
	}
	
	/**
	 * 节点配置
	 * @param element
	 * @return
	 */
	public AbstractConfig elements(AbstractElement element) {
		if(null != element) {
			this.elements.add(element);
		}
		return this;
	}
	
	/**
	 * 节点配置
	 * @param element
	 * @return
	 */
	public AbstractConfig elements(AbstractElement element, AbstractElement... element2) {
		if(null != element) {
			this.elements.add(element);
		}
		if(null != element2) {
			for (AbstractElement abstractElement : element2) {
				if(null != abstractElement) {
					this.elements.add(abstractElement);
				}
			}
		}
		return this;
	}
	
	/**
	 * 获取配置
	 * @return
	 */
	public List<AbstractElement> getElements() {
		return this.elements;
	}
	
	/**
	 * 字符编码
	 * @param charset
	 * @return
	 */
	public abstract AbstractConfig charset(String charset);
	/**
	 * 线程数
	 * @param thread
	 * @return
	 */
	public abstract AbstractConfig thread(int thread);
	/**
	 * 超时时间
	 * @param timeout
	 * @return
	 */
	public abstract AbstractConfig timeout(int timeout);
	/**
	 * 睡眠时间
	 * @param sleeptime
	 * @return
	 */
	public abstract AbstractConfig sleeptime(int sleeptime);
	/**
	 * 设置域名
	 * @param domain
	 * @return
	 */
	public abstract AbstractConfig domain(String domain);
	/**
	 * 失败重复次数
	 * @param cycle
	 * @return
	 */
	public abstract AbstractConfig cycleRetryTimes(int cycle);
	/**
	 * Cookie
	 * @param cookie
	 * @return
	 */
	public abstract AbstractConfig addCookieConfig(Cookie cookie);
	/**
	 * Cookie
	 * @param cookie
	 * @return
	 */
	public abstract AbstractConfig addCookieConfig(Cookies cookie);
	/**
	 * Header
	 * @param header
	 * @return
	 */
	public abstract AbstractConfig addHeaderConfig(Header header);
	/**
	 * Header
	 * @param header
	 * @return
	 */
	public abstract AbstractConfig addHeaderConfig(Headers header);

	/**
	 * 回调
	 * @param abstractCallBack
	 * @return
	 */
    public abstract AbstractConfig callback(AbstractCallBack abstractCallBack);
}
